package problem209;


//209.长度最小的子数组
//https://leetcode.cn/problems/minimum-size-subarray-sum/

class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int sum = 0, ret = Integer.MAX_VALUE;
        for(int i = 0, j = 0; j<n; j++) {
            sum += nums[j];
            while(sum >= target) {
                ret = Math.min(ret, j-i+1);
                sum -= nums[i];
                i++;
            }
        }
        return ret==Integer.MAX_VALUE ? 0 : ret;
    }
}